package com.yupi.oj.job.userai;

import com.yupi.oj.mapper.RecordAiNumberMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UserInvokeAi {
    @Autowired
    private RecordAiNumberMapper recordAiNumberMapper;

    /**
     * 每天 0:00 重置 record_ai_number 表中的 number 字段为 0
     */
    @Scheduled(cron = "0 0 0 * * ?") // 每天 0:00 执行
    public void resetAiNumberDaily() {
        try {
            recordAiNumberMapper.resetNumber(); // 调用 Mapper 方法重置 number 字段
            log.info("record_ai_number 表中普通用户的 number 字段已重置为 0");
        } catch (Exception e) {
            log.error("重置 record_ai_number 表的 number 字段失败", e);
        }
    }
}
